
/*
 *
 * All Rights Reserved.
 */
package com.model.demo.designmodel.proxy.dynamicproxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Matchmaker
 *
 * @author Liao Dongshan, 2019年06月04日
 *
 */
public class Matchmaker implements InvocationHandler {

    private Person target;

    public Object getInstance(Person person){
        this.target=person;
        Class<?> targetClass = target.getClass();
        return Proxy.newProxyInstance(targetClass.getClassLoader(),targetClass.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(this.target, args);
        after();
        return invoke;
    }

    public void before(){
        System.out.println("【前期工作】：确认需求");
    }

    public void after(){
        System.out.println("【后期工作】：反馈结果");
    }
}
